package com.wanwanbear.www.controller;

import com.wanwanbear.www.pojo.NewResult;
import com.wanwanbear.www.pojo.User;
import com.wanwanbear.www.service.FindUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by wz on 2017/6/6.
 */
@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private FindUser findUser;

    @RequestMapping("/{id}")
    @ResponseBody
    private User getUserById(@PathVariable int id){
        User user = findUser.selectByIdFindUser(id);
        return user;
    }
    @RequestMapping("/{before}/{end}")
    @ResponseBody
    private List<User> getOnCriteria(@PathVariable int before,@PathVariable int end){
        System.out.println("before:"+before+"end:"+end);
        return findUser.getOnCriteria(before, end);
    }
    @RequestMapping("/item")
    @ResponseBody
    private User getUser(@RequestParam(defaultValue = "1") int id){
        User user = findUser.getItem(id);
        return user;
    }
    @RequestMapping("/insert")
    @ResponseBody
    private NewResult insertUser(@RequestParam(defaultValue = "") String username, @RequestParam int age){
        System.out.println("insertUser");
        return findUser.insertUser(username,age);
    }
    @RequestMapping("/netty")
    @ResponseBody
    private NewResult userNetty(){
        System.out.println("netty");
        return findUser.userNetty();
    }
}
